<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>闭包计数器</title>
</head>

<script>

//    闭包计数器

function  counter() {
    var  i = 0;

    var cnt = function(){
        return ++i;
    }

    return cnt;
}

    var inc = counter();

    alert(inc());
    alert(inc());
    alert(inc());


</script>
<body>

</body>
</html>